package com.example.controller;

import com.example.common.Result;
import com.example.pojo.News;
import com.example.service.NewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/news")
public class NewsController {

    @Autowired
    private NewsService newsService;


//    根据id查询新闻
    @GetMapping
    public Result getNewsById(@RequestParam Integer id){
       News news =  newsService.selectById(id);
       return Result.success(news);
    }

//    查询全部的新闻
    @GetMapping("/selectAll")
    public Result selectAll(){
      List<News> newsList = (List<News>) newsService.selectAll();
        return Result.success(newsList);
    }

//    新增新闻
    @PostMapping("/add")
    public Result addNews(@RequestBody News news){
        newsService.addNews(news);
        return Result.success();
    }
}
